package net.lab1024.sa.admin.module.business.yct.yctofficial.service;

import java.util.List;

import net.lab1024.sa.admin.module.business.category.domain.vo.CategoryTreeVO;
import net.lab1024.sa.admin.module.business.category.manager.CategoryCacheManager;
import net.lab1024.sa.admin.module.business.yct.yctofficial.dao.YctOfficialInfoClassDao;
import net.lab1024.sa.admin.module.business.yct.yctofficial.domain.entity.YctOfficialInfoClassEntity;
import net.lab1024.sa.admin.module.business.yct.yctofficial.domain.form.YctOfficialInfoClassAddForm;
import net.lab1024.sa.admin.module.business.yct.yctofficial.domain.form.YctOfficialInfoClassQueryForm;
import net.lab1024.sa.admin.module.business.yct.yctofficial.domain.form.YctOfficialInfoClassUpdateForm;
import net.lab1024.sa.admin.module.business.yct.yctofficial.domain.vo.YctOfficialInfoClassTreeVO;
import net.lab1024.sa.admin.module.business.yct.yctofficial.domain.vo.YctOfficialInfoClassVO;
import net.lab1024.sa.admin.module.business.yct.yctofficial.manager.YctOfficialInfoClassManager;
import net.lab1024.sa.admin.module.business.yct.yctproductinstructions.domain.vo.YctProductInstructionsVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 易齿通官网类目 Service
 *
 * @Author zahngben
 * @Date 2024-09-23 10:00:32
 * @Copyright 01
 */

@Service
public class YctOfficialInfoClassService {

    @Resource
    private YctOfficialInfoClassDao yctOfficialInfoClassDao;

    @Resource
    private YctOfficialInfoClassManager yctOfficialInfoClassManager;

    /**
     * 分页查询
     *
     * @param queryForm
     * @return
     */
    public PageResult<YctOfficialInfoClassVO> queryPage(YctOfficialInfoClassQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<YctOfficialInfoClassVO> list = yctOfficialInfoClassDao.queryPage(page, queryForm);
        PageResult<YctOfficialInfoClassVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
        return pageResult;
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(YctOfficialInfoClassAddForm addForm) {
        YctOfficialInfoClassEntity yctOfficialInfoClassEntity = SmartBeanUtil.copy(addForm, YctOfficialInfoClassEntity.class);
        yctOfficialInfoClassDao.insert(yctOfficialInfoClassEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     * @param updateForm
     * @return
     */
    public ResponseDTO<String> update(YctOfficialInfoClassUpdateForm updateForm) {
        YctOfficialInfoClassEntity yctOfficialInfoClassEntity = SmartBeanUtil.copy(updateForm, YctOfficialInfoClassEntity.class);
        yctOfficialInfoClassDao.updateById(yctOfficialInfoClassEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     *
     * @param idList
     * @return
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        yctOfficialInfoClassDao.batchUpdateDeleted(idList, true);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long classId) {
        if (null == classId){
            return ResponseDTO.ok();
        }

        yctOfficialInfoClassDao.updateDeleted(classId, true);
        return ResponseDTO.ok();
    }

    public ResponseDTO<List<YctOfficialInfoClassTreeVO>> queryTree(YctOfficialInfoClassQueryForm queryForm) {
//        if(null == queryForm.getClassParentId()){
//            queryForm.setClassParentId(NumberUtils.LONG_ZERO);
//        }
//        if(null == queryForm.getDeletedFlag()){
//            queryForm.setClassParentId(NumberUtils.LONG_ZERO);
//        }
        List<YctOfficialInfoClassTreeVO> treeList = yctOfficialInfoClassManager.queryYctOfficialInfoClassTree(queryForm);
        return ResponseDTO.ok(treeList);

    }

    public YctOfficialInfoClassVO select(Long classId) {
        YctOfficialInfoClassEntity yctOfficialInfoClassEntity = yctOfficialInfoClassDao.selectById(classId);
        if (null == yctOfficialInfoClassEntity) {
            return null;
        }

        YctOfficialInfoClassVO updateFormVO = SmartBeanUtil.copy(yctOfficialInfoClassEntity, YctOfficialInfoClassVO.class);
        return updateFormVO;
    }
}
